package com.chatdating.controller;


import com.chatdating.entity.dto.RegisterDto;
import com.chatdating.entity.pojo.Result;
import com.chatdating.service.CosService;
import com.chatdating.utils.EmptyUtil;
import com.fasterxml.jackson.databind.introspect.TypeResolutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/user/fileUpload")
@RestController
public class FileController {

    @Autowired
    private CosService cosService;

    /**
     * 文件上传并且回显
     */
    @PostMapping(consumes =  MediaType.MULTIPART_FORM_DATA_VALUE )
    public String fileUpload(  MultipartFile avatar,      // 单独接收文件
                               MultipartFile xuexinPhoto, // 可选文件
                               MultipartFile idCardPhoto,
                               MultipartFile personalPhoto,
                               MultipartFile tiezi){
        if(EmptyUtil.isNotEmpty(avatar)) {
            String headLoad = cosService.uploadFile(avatar, "head");
            return headLoad;
        }else if(EmptyUtil.isNotEmpty(xuexinPhoto)){
            String backgroundLoad = cosService.uploadFile(xuexinPhoto, "xuexin");
            return backgroundLoad;
        }else if(EmptyUtil.isNotEmpty(idCardPhoto)){
            String idcardLoad = cosService.uploadFile(idCardPhoto, "idcard");
            return idcardLoad;
        }else if(EmptyUtil.isNotEmpty(personalPhoto)) {
            String personalLoad = cosService.uploadFile(personalPhoto, "photos");
            return personalLoad;
        }
        else if(EmptyUtil.isNotEmpty(tiezi)){
            String idcardLoad = cosService.uploadFile(tiezi, "tiezi");
            return idcardLoad;
        }else{
            return null;
        }
    }
}
